#!/bin/bash
#turn_servo

maestro_dir="/home/pi/siweather/maestro"

if [ -z "$1" ]; then echo "Usage: turn_servo <bearing>"; exit 1; fi

connected=`$maestro_dir/./UscCmd --list 2>&1 | grep Maestro | awk '{ print $1}'`
if [ $connected -lt 1 ]; then echo "No Maestro servo controller found!"; exit 1; fi

bearing=$1
servo=`echo "($bearing*11.11+5000+0.5)/1" | bc`
echo "Turning servo to "$bearing" degrees..."
$maestro_dir/./UscCmd --servo 0,$servo &> /dev/null
sleep 3
exit 0
